\chapter{Program structure}
The main structure of the program is a state machine where most of the states are represented by their own classes and threads (See \ref{fig:interface}). The state machine class (\textit{SM}) is the over viewing instance for all tasks. Once started the \textit{SM} starts external threads to run partial tasks, e.g. the procedure to adjust the beam (\textit{Beam}), and  decides when a running thread should be stopped.

\begin{figure}[htb]
\begin{center}
\ifpdf
	\includegraphics[width=1.00\textwidth]{img/Interface.pdf}
\else
%	\includegraphics[scale=0.8]{img/Klassendiagramm.jpg}
\fi
\caption{Process interface}
\label{fig:interface}
\end{center}
\end{figure}

The main class is the starting procedure of the state machine and the graphical Interface. All following active instances are to be called from the \textit{StateMachine} class or the \textit{Opcom} class.

\section{Main class}
This class creates an instance of the Opcom and the State Machine class, exchanges references (connects them) and starts both. It is the entering point to start the program.

\section{Opcom class}
The Opcom class contains the graphical user interface (GUI) for the process (see also \ref{user_interface}). It contains graphs of the current beam angle, the current beam reference, the current ball position, the current ball position reference and the controller output. The main control tab includes an output text area to print state changes or other process information onto the screen and buttons to stop and start the process. Through a tabbed panel the user can tune all parameter \textit{DoubleFields} of the different partial tasks. 

\section{StateMachine class}
This class implements a state machine. It creates instances of the active "state-classes" \textit{Beam}, \textit{BallAndBeam} and \textit{Throw} and starts or stops them. It sets also the references for the controllers. A detailed description is found in chapter \ref{chap:statemachine}.

\section{BeamController class}
With the help of a PID-Controller this class positions the Beam (see also \ref{sec:beam}). The reference angle is set by the state machine instance. The class provides a method to check if a set point is reached. The method (\textit{public boolean hasreached(double $y$, double $y_{Ref}$, double $epsilon$)}) returns \textbf{true} if $y$ is located in an $epsilon$ area around $y_{Ref}$. This method and the signal from the light sensor is used by the state machine to determine if the final position is reached.

\section{BeamAndBallController class}
The BeamAndBallController class uses the same principles as in the laboratory to control the ball on the beam (see also \ref{sec:ball}). The control is cascaded PID angle and PID ball position control. The control should be robust enough to handle the different kinds of ball sizes.\\
It also contains a method to estimate the size of the ball, depending on the control effort while holding the ball in a specified position. The reference generation is also done by the state machine. 

\section{Throw class}
The Throw class implements the throwing (or dropping) process of the balls (see also \ref{chap:throw}). This task uses the beam and ball controller instances. It runs its own state machine which realizes the throw strategy depending on the recognized ball size. 